<template>
	<view>
		<camera device-position="back" flash="off" @error="error" style="width: 100%; height: 300px;"></camera>
		<image mode="widthFix" :src="src"></image>
		<button type="primary" @click="takePhoto">拍照</button>
		<button type="primary" @click="submit">确定</button>
	</view>
</template>

<script>
	import {ref,reactive,toRefs} from 'vue'
	import http from '../../utils/http.js'
	export default {
		setup(){
			let data=reactive({
				src:'',
				takePhoto() {
				    const ctx = uni.createCameraContext();
				    ctx.takePhoto({
				        quality: 'high',
				        success: (res) => {
				            data.src = res.tempImagePath
							console.log(data.src)
							// uni.chooseImage({
							// 	count: 1,
							// 	sourceType: ['camera'],
							// 	success: function (res) {
							// 		uni.saveImageToPhotosAlbum({
							// 			filePath: res.tempFilePaths[0],
							// 			success: function () {
							// 				console.log('save success');
							// 			}
							// 		});
							// 	}
							// });
				        }
				    });
				},
				error(e) {
				    console.log(e.detail);
				},
				// submit:()=>{
					// http({
					// 	url:'/taketouxiangphoto',
					// 	data:{
					// 		y_imgsrc:data.src
					// 	},
					// 	method:'post'
					// }).then((res)=>{
					// 	console.log(res.data)
					// })
				// }
			})
			return{...toRefs(data)}
		}	
	}
</script>

<style>

</style>
